<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="产值统计表" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link href="/css/Query.css" rel="stylesheet" type="text/css">
<link href="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="/css/BillList.css" />
<script src="/js/QueryList.js"></script>
<script src="/js/popup_ext.js"></script>
<script src="/calendar/dhtmlgoodies_calendar/dhtmlgoodies_calendar.js"></script>
<script language="javascript">
	function checkDateStr(){
		var startDate=document.getElementById("start_date").value;
		if(startDate==null || startDate==''){
			ShowAlert('提示框','请选择开始日期',200,100);
			return false;
		}else{
			var arr=startDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','开始日期格式不正确',200,100);
				return false;
			}
		}
		var endDate=document.getElementById("end_date").value;
		if(endDate==null || endDate==''){
			ShowAlert('提示框','请选择结束日期',200,100);
			return false;
		}else{
			var arr=endDate.split("-");
			if(arr.length==null || arr.length!=3){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}else if(isNaN(arr[0]) || isNaN(arr[1]) || isNaN(arr[2])){
				ShowAlert('提示框','结束日期格式不正确',200,100);
				return false;
			}
		}
		return true;
	}
	function createPageParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("end_date").value);
		str=str+"&sta_name="+encodeURIComponent(document.getElementById("sta_name").value);
		str=str+"&dep_id="+document.getElementById("dep_id").value;
		str=str+"&ts_id="+document.getElementById("ts_id").value;
		
		return str;
	}
	
	function createProgramParaStr(){
		var str="start_date="+encodeURIComponent(document.getElementById("hid_start_date").value);
		str=str+"&end_date="+encodeURIComponent(document.getElementById("hid_end_date").value);
		str=str+"&sta_name="+encodeURIComponent(document.getElementById("hid_sta_name").value);
		str=str+"&dep_id=${depId}";
		str=str+"&ts_id=${tsId}";
		
		return str;
	}

	function doSearch(){
		var str;
		if(IsAdvSearch){//高级
			str="search_type=1";
			if(document.getElementById("cb_date").checked){
				if(checkDateStr()){
					str=str+"&cb_date=1";
				}else{
					return;
				}
			}
			if(document.getElementById("cb_dep").checked){
				var depId=document.getElementById("dep_id").value;
				if(depId==null || depId=="" || depId=="0"){
					ShowAlert('提示框','请选择部门',200,100);
					return;
				}
				str=str+"&cb_dep=1";
			}
			if(document.getElementById("cb_sta").checked){
				var staName=document.getElementById("sta_name").value.trim();
				if(staName==null || staName==""){
					ShowAlert('提示框','请输入员工姓名',200,100);
					return;
				}
				str=str+"&cb_sta=1";
			}
			if(document.getElementById("cb_ts").checked){
				var tsId=document.getElementById("ts_id").value;
				if(tsId==null || tsId=="" || tsId=="0"){
					ShowAlert('提示框','请选择帐套',200,100);
					return;
				}
				str=str+"&cb_ts=1";
			}
		}else{//快速
			str="search_type=2";
			if(!checkDateStr()){
				return;
			}
		}
		var paraStr=createPageParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		window.location="/make/OvCount.ihtm?"+str;
	}
	function doGo(pageIndex){
		var str=getSearchCondition();
		str=str+"&current_page="+pageIndex;
		window.location="/make/OvCount.ihtm?"+str;
	}
	function getSearchCondition(){
		var searchType="${searchType}";
		var str="search_type="+searchType;
		if(searchType=="1"){//高级
			<c:if test="${cbDate=='1'}">str=str+"&cb_date=1";</c:if>
			<c:if test="${cbDep=='1'}">str=str+"&cb_dep=1";</c:if>
			<c:if test="${cbSta=='1'}">str=str+"&cb_sta=1";</c:if>
			<c:if test="${cbTs=='1'}">str=str+"&cb_ts=1";</c:if>
		}else{//快速
			
		}
		
		var paraStr=createProgramParaStr();
		if(paraStr!=""){
			str=str+"&"+paraStr;
		}
		
		return str;
	}
	function doJump(pageIndex){
		if(window.event.keyCode==13){
			doGo(pageIndex);
		}
	}
	function DoubleClick(it){
		
	}
	function doDownload(){
		var str=getSearchCondition();
		window.location="/make/OvCount.ihtm?content_type=EXCEL&"+str;
	}
	function doCancel(){
		window.close();
	}
	function doInit(){
		//Window_Onload();
	}
	function checkInput(){
		if(window.event.keyCode==13){
			doSearch();
		}
	}
	function doAutoCheck(objId){
		document.getElementById(objId).checked=true;
	}
	function selectStafferName(objId,checkObjId){
		var url="/base/StafferMainForSelect.ihtm";
		var cb="selectStafferNameCallBack('"+objId+"','"+checkObjId+"')";
		ShowIframe("选择员工",url,800,500,cb,900,600);
	}
	function selectStafferNameCallBack(objId,checkObjId){
		if(popRetVal!=null){
			var arr=popRetVal.split(";");
			document.getElementById(objId).value=arr[1];
			doAutoCheck(checkObjId);
		}
	}
	function setDate(type){
		var d=new Date();
		var startStr="";
		var endStr="";
		if(type=="CURRENT_MONTH"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-01";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="PREVIEW_MONTH"){
			d=new Date(d.getFullYear(),d.getMonth(),1);
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-1";
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="TODAY"){
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}else if(type=="YESTERDAY"){
			d.setDate(d.getDate()-1);
			startStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			endStr=d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
		}
		document.getElementById("start_date").value=startStr;
		document.getElementById("end_date").value=endStr;
		doAutoCheck("cb_date");
	}
	function showDetail(staId,staName,type){
		var str="search_type=1";
		<c:if test="${searchType!=1 || cbDate=='1'}">str=str+"&cb_date=1&start_date=${startDate}&end_date=${endDate}";</c:if>
		<c:if test="${cbDep=='1'}">str=str+"&cb_dep=1&dep_id=${depId}";</c:if>
		<c:if test="${cbTs=='1'}">str=str+"&cb_ts=1&ts_id=${tsId}";</c:if>
		if(staId!=0){
			str=str+"&cb_sta=1&sta_id="+staId+"&sta_name="+encodeURIComponent(staName);
		}
		var url="";
		if(type=='MNG'){
			url="OvBusinessList.ihtm?"+str;
			showWin(900,600,url);
		}else if(type=='FOL'){
			url="OvFollowList.ihtm?"+str;
			showWin(900,600,url);
		}else if(type=='DES'){
			url="OvDesignList.ihtm?"+str;
			showWin(900,600,url);
		}else if(type=='MAK'){
			url="OvMakeList.ihtm?"+str;
			showWin(1024,600,url);
		}else if(type=='REC'){
			url="OvReceiveList.ihtm?"+str;
			showWin(900,600,url);
		}else if(type=='SET'){
			url="OvSetuList.ihtm?"+str;
			showWin(1024,600,url);
		}else if(type=='BILL'){
			url="/make/OvBillSearchResult.ihtm?cb_exa=1&exa=Y&"+str;
			showWin(900,600,url);
		}else if(type=='SAL'){
			url="OvSaleList.ihtm?"+str;
			showWin(900,600,url);
		}
	}
</script>
</head>
<body oncontextmenu="return false">
<div class="Wrap"><!-- 页面主框架 -->
    
	<div id="ListContainer" class="Container"><!-- 主体容器 -->
	    
	    <!-- 标题栏 -->
	    <div class="Heading BillIcon">
	        <div class="HeadingContent">
	            <h1>产值统计表</h1>
	            <span class="Note">统计指定期间员工的产值，按产值从大到小排列</span>
	        </div>
	    </div>
	
		<!-- 主内容 -->
		<div class="Content">
	        <!-- 筛选控件栏 -->
	        <div class="FilterBar ClearFix">
	            <div class="SearchIcon"></div>
	            <span class="fl">
	            	<table class="MoreOption" cellpadding="0" cellspacing="0">
	            		<th class="c1" width="80px">
	            			<input type="checkbox" name="cb_date" id="cb_date" <c:if test="${cbDate=='1' || searchType=='2'}">checked="true"</c:if> style="visibility:hidden;" />
	            			日期
	            		</th>
	            		<td width="360px">
	            			<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_date');" id="start_date" name="start_date" value="<c:out value="${startDate}" />">
							<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('start_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_date\')');">
							<input type="hidden" id="hid_start_date" value="<c:out value="${startDate}" />">
				            	至
							<input type="text" class="TextBox Datetime" maxlength="15" onKeyUp="checkInput();" id="end_date" name="end_date" value="<c:out value="${endDate}" />">
							<img src="/images/calendar.gif" class="imgIconButton" onClick="displayCalendar(document.getElementById('end_date'),'yyyy-mm-dd',this,false,'doAutoCheck(\'cb_date\')');">
							<input type="hidden" id="hid_end_date" value="<c:out value="${endDate}" />">
							<a href="javascript:setDate('CURRENT_MONTH');">本月</a>
							<a href="javascript:setDate('TODAY');">今天</a>
							<a href="javascript:setDate('YESTERDAY');">昨天</a>
							<a href="javascript:setDate('PREVIEW_MONTH');">上月</a>
	            		</td>
	            	</table>
	            </span>
	            <span class="fr">
	            	<a href="javascript:;" id="lnkMoreOption">更多查询选项</a>
	            	<input type="button" value=" 查 询" onClick="doSearch();" class="buttom search-but" id="sSearchButton" name="sSearchButton">
					<input type="button" value=" 导 出" onClick="doDownload();" class="buttom search-out" id="sDownloadButton" name="sDownloadButton" <c:if test="${currentUser.user.userType!=1 && fn:indexOf(currentUser.privs,';NO_EXPO;')!=-1}">disabled="true"</c:if>>
	            </span>
				<div id="dvMoreOptionBox" class="MoreOptionBox" style="display:none;">
					<table class="MoreOption" cellpadding="0" cellspacing="0">
						<tr>
							<th class="c1" width="80px">
			        			<input type="checkbox" name="cb_dep" id="cb_dep" <c:if test="${cbDep=='1'}">checked="true"</c:if>>
			        			部门
			        		</th>
			        		<td class="c3" width="180px">
			        			<select id="dep_id" name="dep_id" onFocus="doAutoCheck('cb_dep');">
									<option value="0">==请选择==</option>
	  								<commonTag:createSelectTree list="${depList}" emptyOption="0" defaultValue="${depId}" />
	  							</select>
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_sta" id="cb_sta" <c:if test="${cbSta=='1'}">checked="true"</c:if>>
			        			员工
			        		</th>
			        		<td class="c3">
			        			<input type="text" class="TextBox" maxlength="15" name="sta_name" id="sta_name" onKeyUp="checkInput();" onFocus="doAutoCheck('cb_sta');" value="<c:out value="${staName}" />" >
								<img class="imgIconButton" src="/images/make-a.gif" onClick="selectStafferName('sta_name','cb_sta');" />
								<input type="hidden" id="hid_sta_name" value="<c:out value="${staName}" />">
			    			</td>
			    		</tr>
			    		<tr>
							<th class="c1">
			        			<input type="checkbox" name="cb_ts" id="cb_ts" <c:if test="${cbTs=='1'}">checked="true"</c:if>>
			        			账套
			        		</th>
			        		<td class="c3">
			        			<select name="ts_id" id="ts_id" onFocus="doAutoCheck('cb_ts');">
					  				<option value="0">==请选择账套==</option>
					  				<c:forEach var="item" items="${tsList}">
					  				<option value="${item.id}" <c:if test="${tsId==item.id}">selected</c:if>>${item.title}</option>
					  				</c:forEach>
				  				</select>
			    			</td>
			    		</tr>
			    	</table>
			    	
					<div class="OptionOrderBy">
	                    <span class="fr"><a href="javascript:;" id="lnkHiddenOption">隐藏查询选项</a></span>
	                </div>
				</div>
			</div>
			
			<!-- 提示信息显示栏 -->
	        <div class="MsgBar">
	            <%@include file="../inc/AlertMsg.jsp"%>
	        </div>
	        
		    <div class="table-list">
		        <table width="100%">
		          	<tr>
						<th width="4%" rowspan="2">序号</th>
						<th width="8%" rowspan="2">部门</th>
						<th width="7%" rowspan="2">姓名</th>
						<th width="7%" rowspan="2">职位</th>
						<th width="66%" colspan="8">当期产值</th>
						<th width="8%" rowspan="2">营销产值</th>
				  	</tr>
				 	<tr>
						<th width="8%">接单</th>
						<th width="8%">跟单</th>
						<th width="8%">设计</th>
						<th width="8%">制作</th>
						<th width="8%">收欠费</th>
						<th width="8%">安装</th>
						<th width="8%">其他产值</th>
						<th width="10%">合计</th>
				  	</tr>
				  	<c:forEach var="item" items="${list}" varStatus="i">
					<c:if test="${(i.index mod 2)==0}"><c:set var="trClass" value="query_list_data_tr1" /></c:if>
					<c:if test="${(i.index mod 2)!=0}"><c:set var="trClass" value="query_list_data_tr2" /></c:if>
					<tr class="${trClass}" index="${i.index+1}" onmouseout='javascript:mouseout(this)' onmouseover='javascript:mouseover(this)'>
						<td>${i.index+1}</td>
						<td>
							${item.values[1]}
							<input type="radio" name='query_checkbox' value="${item.values[0]}" style="display:none">
						</td>
						<td>${item.values[2]}</td>
						<td>${item.values[3]}</td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','MNG');"><c:if test="${item.values[4]!=0.00}">${item.values[4]}</c:if></a></td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','FOL');"><c:if test="${item.values[5]!=0.00}">${item.values[5]}</c:if></a></td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','DES');"><c:if test="${item.values[6]!=0.00}">${item.values[6]}</c:if></a></td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','MAK');"><c:if test="${item.values[7]!=0.00}">${item.values[7]}</c:if></a></td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','REC');"><c:if test="${item.values[8]!=0.00}">${item.values[8]}</c:if></a></td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','SET');"><c:if test="${item.values[9]!=0.00}">${item.values[9]}</c:if></a></td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','BILL');"><c:if test="${item.values[10]!=0.00}">${item.values[10]}</c:if></a></td>
						<td><c:if test="${item.values[11]!=0.00}">${item.values[11]}</c:if></td>
						<td><a href="javascript:showDetail(${item.values[0]},'${item.values[2]}','SAL');"><c:if test="${item.values[12]!=0.00}">${item.values[12]}</c:if></a></td>
					</tr>
				  	</c:forEach>
				  	<tr>
						<th colspan="4">合计</th>
						<th><a href="javascript:showDetail(0,'','MNG');"><c:if test="${totalArr[0]!=0.00}">${totalArr[0]}</c:if></a></th>
						<th><a href="javascript:showDetail(0,'','FOL');"><c:if test="${totalArr[1]!=0.00}">${totalArr[1]}</c:if></a></th>
						<th><a href="javascript:showDetail(0,'','DES');"><c:if test="${totalArr[2]!=0.00}">${totalArr[2]}</c:if></a></th>
						<th><a href="javascript:showDetail(0,'','MAK');"><c:if test="${totalArr[3]!=0.00}">${totalArr[3]}</c:if></a></th>
						<th><a href="javascript:showDetail(0,'','REC');"><c:if test="${totalArr[4]!=0.00}">${totalArr[4]}</c:if></a></th>
						<th><a href="javascript:showDetail(0,'','SET');"><c:if test="${totalArr[5]!=0.00}">${totalArr[5]}</c:if></a></th>
						<th><a href="javascript:showDetail(0,'','BILL');"><c:if test="${totalArr[6]!=0.00}">${totalArr[6]}</c:if></a></th>
						<th><c:if test="${totalArr[7]!=0.00}">${totalArr[7]}</c:if></th>
						<th><a href="javascript:showDetail(0,'','SAL');"><c:if test="${totalArr[8]!=0.00}">${totalArr[8]}</c:if></a></th>
				  	</tr>
				</table>
			</div>
			
		</div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">
	function ChangeWindowSize( container, maxWidth ){
	    setTimeout( function(){
	        var w1 = document.documentElement.clientWidth-40;
	        if( w1>maxWidth ) w1 = maxWidth;
	        else if( w1<970 ) w1 = 960;
	        container.style.width = w1+'px';
	    }, 300 );
	}
	var IsAdvSearch = false;
	(function(){
		doInit();
	    var ListContainer = document.getElementById('ListContainer');
	    ChangeWindowSize( ListContainer, 2020 );    // 超过 1280 的最大 1260 ，不全部铺满
	
	    var lnkMoreOption   = document.getElementById('lnkMoreOption');
	    var lnkHiddenOption = document.getElementById('lnkHiddenOption');
	    lnkMoreOption.onclick = function(){
	    	IsAdvSearch = true;
	        document.getElementById('dvMoreOptionBox').style.display = 'block';
	        document.getElementById('cb_date').style.visibility = 'visible';
	        this.style.visibility = 'hidden';
	    };
	    lnkHiddenOption.onclick = function(){
	    	IsAdvSearch = false;
	        document.getElementById('dvMoreOptionBox').style.display = 'none';
	        document.getElementById('cb_date').style.visibility = 'hidden';
	        lnkMoreOption.style.visibility = 'visible';
	    };
	})();
</script>
